home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / GRAPHICS.SWG / 0160_Gravity display.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  3KB  |  86 lines

  1. {gravity type program modified by ■Mr. Krinkle■}
  2. uses {vgaSCRN,}crt;
  3. const Balls = 900;  {if program too fast increase: if too slow decrease}
  4.  
  5. type movement= record
  6.      x,   y : integer;  { position }
  7.     dx,  dy : integer;  { velocity }
  8.    ddx, ddy : integer;  { acceleration }
  9.    color    : integer;
  10.    MaxYValue: integer;
  11. END;
  12.  
  13. VAR ch : char;           {for readkey}
  14.     I  : integer;
  15.   Ball : array[1..BAlls] of movement;
  16.  
  17. procedure PutDot(x,y,color:integer);
  18.   begin
  19.     Mem[$a000{VGA_Segment}:(y*320)+x] := color;
  20.   end;
  21. Procedure VideoMode ( Mode : Byte );
  22.     Begin { VideoMode }
  23.       Asm
  24.         Mov  AH,00
  25.         Mov  AL,Mode
  26.         Int  10h
  27.       End;
  28.     End;  { VideoMode }
  29.  
  30. BEGIN {MAIN}
  31. videoMODE($13); {320x200x256c}
  32. {init all balls}
  33. FOR I:=1 to BAlls do BEGIN
  34. With ball[i] do BEGIN
  35. ddx := 0;             { constant horizontal acceleration }  {gravity < or >}
  36. ddy := 0;             { constant vertical acceleration } {gravity ^ or v }
  37.  
  38. { in this case there is NO gravity pull from ANY direction: ... weightless}
  39.  
  40.  dx := Random(2)-1;             { initial velocity < or >}
  41.  dy := -1;                      { initial velocity ^ or v}
  42.  
  43.   x := i mod 305+random(15)+1; { initial coordinates, as }
  44.   y := I mod 190+random(10)+1; {   you specified }
  45.  
  46. {320 * 200 positioning : take I and remainder when divided by 'balls'
  47.                          to produce a sequential increment that
  48.                          does not over flow 320 or 200; plus a random
  49.                          to give the fuzzy line effect}
  50.  
  51.   color:=Random( I div ((I div 254)+1)) + 1;  {Each Balls color}
  52.                    { This formula will take a loop from 1 to [any number]
  53.                      and make it so it will increment from 1 to 255
  54.                      [valid color assignments]}
  55.   MaxYValue:=Y+1;  {future use only}
  56. END; {with}
  57. END; {for do loop}
  58.  
  59.  
  60. WHILE not(keypressed) do begin
  61.  FOR i:=1 to Balls do BEGIN
  62.   With ball[i] do BEGIN
  63.   putdot(x, y, 0);    { blank out the pixel drawn on the last iteration }
  64.   dx := dx + ddx;     { updating velocity }
  65.   dy := dy + ddy;
  66.   x  :=  x +  dx;     { updating position }
  67.   y  :=  y +  dy;
  68.   IF x< 1 then begin      {hits left of screen}
  69.      X:=1;
  70.      dx:=dx*-1;           {moves it to the right}
  71.   End;
  72.   IF x > 319 then begin   {hits right of screen}
  73.      x :=319;
  74.      dx:=-dx;             {moves it to the left}
  75.   END;
  76.   IF y > 190 then begin   { BOUNCE! }
  77.     y := 190;
  78.     dy := -dy;            {not used: all object float upward not down}
  79.   End;
  80.   putdot(x, y, color);  { draw the pixel at the new position }
  81.   END; {WITH}
  82.  END; {for do loop}
  83. End; {KEYPRESS}
  84. videoMODe($3);          {back to text mode}
  85. end. {PROGRAM}
  86.